package com.education.platform.management.controller.common;



import com.education.platform.common.enums.DicTypeEnum;
import com.education.platform.common.enums.RedisCountTypeEnum;
import com.education.platform.common.enums.SmsTypeEnum;
import com.education.platform.common.exception.AssertException;
import com.education.platform.common.exception.BusinessException;
import com.education.platform.common.service.entity.PageDTO;
import com.education.platform.common.util.BeanUtil;
import com.education.platform.common.util.StringUtils;
import com.education.platform.common.util.ValidatorUtils;
import com.education.platform.dao.entity.*;
import com.education.platform.management.service.SysDictionaryService;
import com.education.platform.management.vo.response.SysDictionaryResponseVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.*;
import java.util.stream.Collectors;

/**
* describe: 通用功能
* @author : tomato
* @date: 2020-06-07 11:38:44.106
**/
@RestController
@Api("通用功能")
@RequestMapping("common")
@Validated
public class CommonController {

    private static final Logger LOGGER = LoggerFactory.getLogger(CommonController.class);

	@Autowired
    private SysDictionaryService sysDictionaryService;


    @ApiOperation(value = "获取年级")
    @PostMapping("selectGrade")
    public List<SysDictionaryResponseVO> selectGrade() {
        Map<String, List<SysDictionaryResponseVO>> map = new HashMap<>(2);
        List<String> typeCodes = Arrays.asList(DicTypeEnum.MIDDLE_GRADE.getValue(), DicTypeEnum.HIGH_GRADE.getValue());
        List<SysDictionaryDO> dictionaryDTOS = sysDictionaryService.getListByDicTypeCodeList(typeCodes);
        List middles = dictionaryDTOS.parallelStream().filter(m -> DicTypeEnum.MIDDLE_GRADE.getValue().equals(m.getTypeCode())).collect(Collectors.toList());
        List highs = dictionaryDTOS.parallelStream().filter(m -> DicTypeEnum.HIGH_GRADE.getValue().equals(m.getTypeCode())).collect(Collectors.toList());

        middles = BeanUtil.convert(middles, SysDictionaryResponseVO.class);
        highs = BeanUtil.convert(highs, SysDictionaryResponseVO.class);
        List<SysDictionaryResponseVO> result = new ArrayList<>();
        result.addAll(middles);
        result.addAll(highs);
        return result;
    }
    @ApiOperation(value = "获取学校")
    @GetMapping("selectSchool")
    public List<SysDictionaryResponseVO> selectSchool() {
        List<String> typeCodes = Arrays.asList(DicTypeEnum.SCHOOL.getValue());
        List<SysDictionaryDO> dictionaryDTOS = sysDictionaryService.getListByDicTypeCodeList(typeCodes);
        List<SysDictionaryResponseVO> result = new ArrayList<>();
        result.addAll(BeanUtil.convert(dictionaryDTOS,SysDictionaryResponseVO.class));
        return result;
    }

    @ApiOperation(value = "获取课程标签")
    @GetMapping("selectTags")
    public List<SysDictionaryResponseVO> selectTags() {
        List<String> typeCodes = Arrays.asList(DicTypeEnum.COURSE_TAG.getValue());
        List<SysDictionaryDO> dictionaryDTOS = sysDictionaryService.getListByDicTypeCodeList(typeCodes);
        List<SysDictionaryResponseVO> result = new ArrayList<>();
        result.addAll(BeanUtil.convert(dictionaryDTOS,SysDictionaryResponseVO.class));
        return result;
    }

    @ApiOperation(value = "获取中考分类")
    @GetMapping("selectMiddleExamType")
    public List<SysDictionaryResponseVO> selectMiddleExamType() {
        List<String> typeCodes = Arrays.asList( DicTypeEnum.MIDDLE_EXAM.getValue());
        List<SysDictionaryDO> dictionaryDTOS = sysDictionaryService.getListByDicTypeCodeList(typeCodes);
        List<SysDictionaryResponseVO>  middles = BeanUtil.convert(dictionaryDTOS, SysDictionaryResponseVO.class);
        return middles;
    }
    @ApiOperation(value = "获取高考分类")
    @GetMapping("selectHighExamType")
    public List<SysDictionaryResponseVO> selectHighExamType() {
        List<String> typeCodes = Arrays.asList( DicTypeEnum.HIGH_EXAM.getValue());
        List<SysDictionaryDO> dictionaryDTOS = sysDictionaryService.getListByDicTypeCodeList(typeCodes);
        List<SysDictionaryResponseVO>  middles = BeanUtil.convert(dictionaryDTOS, SysDictionaryResponseVO.class);
        return middles;
    }

}
